package algorithm.子数组达到规定累加和的最大长度系列问题.转圈问题;

public class PrintMatrixSpiralOrder {

    public static void spiralOrderPrint(int[][] arr){
        int size = arr.length / 2;
        for (int i = 0; i < size; i++) {
            printEdge(arr, i);
        }
    }

    public static void printEdge(int[][] arr, int index){
        int length = arr.length - index * 2;
        int index1 = index;
        int index2 = index + length -1;
        for (int i = index1; i < index2; i++) {
            System.out.println(arr[index1][i]);
        }
        for (int i = index1; i < index2; i++) {
            System.out.println(arr[i][index2]);
        }
        for (int i = index2; i > index1; i--) {
            System.out.println(arr[index2][i]);
        }
        for (int i = index2; i > index1; i--) {
            System.out.println(arr[i][index1]);
        }
    }
    public static void main(String[] args) {
        int[][] matrix = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 },
                { 13, 14, 15, 16 } };
        spiralOrderPrint(matrix);

    }

}
